<template>
  <div class="articleNew">
    <van-nav-bar title="文章详情" left-arrow @click-left="$router.back()" />
    <!-- 文章部分 -->
    <div class="article-wrap">
      <h3 class="title">{{ info.title }}</h3>
      <div class="auto-info">
        <van-image fit="cover" round :src="info.aut_photo" />
        <div class="info">
          <div>{{ info.aut_name }}</div>
          <div class="time">{{ info.pubdate | relvTime }}</div>
        </div>
        <van-button class="wrapbtn" icon="plus" type="info" round
          >关注</van-button
        >
      </div>
      <!-- 文章内容 -->
      <div class="content" v-html="info.content"></div>
      <!-- 分割线 -->
      <van-divider>end</van-divider>
      <!-- 点赞和不喜欢的按钮 -->
      <div class="btn-wrap">
        <van-button round icon="good-job-o" type="primary">点赞</van-button>
        <van-button round icon="delete-o" type="danger">不喜欢</van-button>
      </div>
    </div>

    <!-- 评论区 -->
    <comment />
  </div>
</template>

<script>
import { articleNewAPI } from "@/api";
import comment from "./comment";
export default {
  components: {
    comment,
  },
  data() {
    return {
      info: {},
    };
  },

  async created() {
    let res = await articleNewAPI(this.$route.query.id);
    // console.log(res);
    this.info = res.data.data;
  },
};
</script>

<style lang="less" scoped>
.articleNew {
  .article-wrap {
    padding: 0 20px;
    .title {
      margin: 10px 0;
      font-size: 24px;
    }
    .auto-info {
      height: 80px;
      display: flex;
      // 垂直居中
      align-items: center;
      .van-image {
        height: 60px;
        width: 60px;
      }
      .info {
        margin-left: 20px;
        flex: 1;

        .time {
          color: grey;
        }
      }

      .wrapbtn {
        .van-button__icon {
          font-size: 12px;
          color: #fff;
          font-weight: 700;
        }
      }
    }

    .content {
      // 如果最后一个单词不够放了，就把整个单词换一行开始写
      word-wrap: break-word;
      // word-break: break-all; 以一行实在放不下了就换行可能会导致单词脱节
      overflow: hidden;
      ::v-deep pre {
        // 自带滚动条
        overflow: auto;
        background-color: #000;
        color: #fff;
      }
      ::v-deep img {
        width: 80%;
      }
    }
    .btn-wrap {
      display: flex;
      justify-content: center;
      .van-button {
        width: 120px;
        background-color: #fff;
        color: #07c160;
        &:last-of-type {
          margin-left: 20px;
          color: red;
        }
      }
    }
  }
}
</style>